package com.lyf.scm.plan.domain.remote.stock.facade;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.domain.remote.basedata.dto.StoreDTO;
import com.lyf.scm.plan.domain.remote.stock.StockCenterRemote;
import com.lyf.scm.plan.domain.remote.stock.StockCoreRemote;
import com.lyf.scm.plan.domain.remote.stock.dto.*;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/9/8 14:48
 */
@Service
@Slf4j
public class StockCoreFacade {

    @Resource
    private StockCoreRemote stockCoreRemote;
    @Resource
    private StockCenterRemote stockCenterRemote;


    public List<RealWarehouse> queryForAdmin(RealWarehouseParamDTO realWarehouseParamDTO){
        log.info("根据省市区批量查询对应的仓库入参:realWarehouseParamDTO:{}", JSON.toJSONString(realWarehouseParamDTO));
        Response<List<RealWarehouse>> response = stockCoreRemote.queryForAdmin(realWarehouseParamDTO);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2001.getCode(),ResponseMsg.EXCEPTION_2001.getMsg());
        }
        return response.getData();
    }

    public List<RealTimeStockDTO> listAvailableQty(QueryRealTimeStockDTO queryRealTimeStockDTO){
        log.info("查询实时库存入参:queryRealTimeStockDTO:{}",JSON.toJSONString(queryRealTimeStockDTO));
        if (ObjectUtil.isNotNull(queryRealTimeStockDTO)) {
            Response<List<RealTimeStockDTO>> response = stockCoreRemote.listAvailableQty(queryRealTimeStockDTO);
            if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
                throw new RomeException(ResponseMsg.EXCEPTION_2001.getCode(),ResponseMsg.EXCEPTION_2001.getMsg());
            }
            return response.getData();
        }
        return null;
    }
    public List<StoreDTO> queryFactoryByRwType(Integer realWarehouseType) {
        Response<List<StoreDTO>> response = stockCenterRemote.queryFactoryByRwType(realWarehouseType);
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
